//
//  XAFirstCollectionViewCell.m
//  SelfDriving
//
//  Created by 薛安 on 2017/6/20.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "XAFirstCollectionViewCell.h"

@implementation XAFirstCollectionViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    _imageView = [[UIImageView alloc] init];
    _imageView.contentMode = UIViewContentModeScaleAspectFill;
    _imageView.clipsToBounds = YES;
//    [self addSubview:_imageView];
    [self.contentView addSubview:_imageView];
    [_imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self).with.insets(0, 0, 0, 0);
    }];
    
    _label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, SCRE_WIDTH / 3, 20)];
    _label.textColor = [UIColor whiteColor];
    _label.backgroundColor = [UIColor clearColor];
    _label.text = @"现场";
    _label.textAlignment = NSTextAlignmentRight;
//    [self addSubview:_label];
    [self.contentView addSubview:_label];
    
    _deleteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_deleteBtn setImage:[UIImage imageNamed:@"删除"] forState:UIControlStateNormal];
    _deleteBtn.hidden = YES;
    [_deleteBtn addTarget:self action:@selector(clickDeleteBtn) forControlEvents:UIControlEventTouchUpInside];
//    [self addSubview:_deleteBtn];
    [self.contentView addSubview:_deleteBtn];
    //宽，高改为30之前是20(xhw11月2号改)
    [_deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.mas_bottom).offset(-5);
        make.right.equalTo(self.mas_right).offset(-5);
        make.width.and.height.equalTo(@40);
    }];
    
    UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPressGesture)];
    [self addGestureRecognizer:longPress];
    
//    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture)];
//    [self addGestureRecognizer:tap];
}

- (void)clickDeleteBtn {
    if (self.delegate && [self.delegate respondsToSelector:@selector(willDeleteACellWithModel:path:)]) {
//        [self.delegate willDeleteACellAtIndexPath:_model];
//        [self.delegate willDeleteACellWithModel:self.model];
        [self.delegate willDeleteACellWithModel:self.model path:self.path];
    }
}

- (void)handleLongPressGesture {
    if (![self.userID isEqualToString:[AppDelegate shareDelegate].user.uid]) {
        return;
    } else if (self.delegate && [self.delegate respondsToSelector:@selector(willShowAllDeleteBtn)]) {
        [self.delegate willShowAllDeleteBtn];
    }
}

//- (void)handleTapGesture {
//    if (self.delegate && [self.delegate respondsToSelector:@selector(willDismissAllDeleteBtn)]) {
//        [self.delegate willDismissAllDeleteBtn];
//    }
//}

@end
